module "wrapper" {
  source = "../../modules/iam-role-for-service-accounts"

  for_each = var.items

  amazon_managed_service_prometheus_workspace_arns                = try(each.value.amazon_managed_service_prometheus_workspace_arns, var.defaults.amazon_managed_service_prometheus_workspace_arns, [])
  attach_amazon_managed_service_prometheus_policy                 = try(each.value.attach_amazon_managed_service_prometheus_policy, var.defaults.attach_amazon_managed_service_prometheus_policy, false)
  attach_aws_gateway_controller_policy                            = try(each.value.attach_aws_gateway_controller_policy, var.defaults.attach_aws_gateway_controller_policy, false)
  attach_cert_manager_policy                                      = try(each.value.attach_cert_manager_policy, var.defaults.attach_cert_manager_policy, false)
  attach_cloudwatch_observability_policy                          = try(each.value.attach_cloudwatch_observability_policy, var.defaults.attach_cloudwatch_observability_policy, false)
  attach_cluster_autoscaler_policy                                = try(each.value.attach_cluster_autoscaler_policy, var.defaults.attach_cluster_autoscaler_policy, false)
  attach_ebs_csi_policy                                           = try(each.value.attach_ebs_csi_policy, var.defaults.attach_ebs_csi_policy, false)
  attach_efs_csi_policy                                           = try(each.value.attach_efs_csi_policy, var.defaults.attach_efs_csi_policy, false)
  attach_external_dns_policy                                      = try(each.value.attach_external_dns_policy, var.defaults.attach_external_dns_policy, false)
  attach_external_secrets_policy                                  = try(each.value.attach_external_secrets_policy, var.defaults.attach_external_secrets_policy, false)
  attach_fsx_lustre_csi_policy                                    = try(each.value.attach_fsx_lustre_csi_policy, var.defaults.attach_fsx_lustre_csi_policy, false)
  attach_fsx_openzfs_csi_policy                                   = try(each.value.attach_fsx_openzfs_csi_policy, var.defaults.attach_fsx_openzfs_csi_policy, false)
  attach_load_balancer_controller_policy                          = try(each.value.attach_load_balancer_controller_policy, var.defaults.attach_load_balancer_controller_policy, false)
  attach_load_balancer_controller_targetgroup_binding_only_policy = try(each.value.attach_load_balancer_controller_targetgroup_binding_only_policy, var.defaults.attach_load_balancer_controller_targetgroup_binding_only_policy, false)
  attach_mountpoint_s3_csi_policy                                 = try(each.value.attach_mountpoint_s3_csi_policy, var.defaults.attach_mountpoint_s3_csi_policy, false)
  attach_node_termination_handler_policy                          = try(each.value.attach_node_termination_handler_policy, var.defaults.attach_node_termination_handler_policy, false)
  attach_velero_policy                                            = try(each.value.attach_velero_policy, var.defaults.attach_velero_policy, false)
  attach_vpc_cni_policy                                           = try(each.value.attach_vpc_cni_policy, var.defaults.attach_vpc_cni_policy, false)
  cert_manager_hosted_zone_arns                                   = try(each.value.cert_manager_hosted_zone_arns, var.defaults.cert_manager_hosted_zone_arns, [])
  cluster_autoscaler_cluster_names                                = try(each.value.cluster_autoscaler_cluster_names, var.defaults.cluster_autoscaler_cluster_names, [])
  create                                                          = try(each.value.create, var.defaults.create, true)
  create_inline_policy                                            = try(each.value.create_inline_policy, var.defaults.create_inline_policy, false)
  create_policy                                                   = try(each.value.create_policy, var.defaults.create_policy, true)
  description                                                     = try(each.value.description, var.defaults.description, null)
  ebs_csi_kms_cmk_arns                                            = try(each.value.ebs_csi_kms_cmk_arns, var.defaults.ebs_csi_kms_cmk_arns, [])
  external_dns_hosted_zone_arns                                   = try(each.value.external_dns_hosted_zone_arns, var.defaults.external_dns_hosted_zone_arns, [])
  external_secrets_kms_key_arns                                   = try(each.value.external_secrets_kms_key_arns, var.defaults.external_secrets_kms_key_arns, [])
  external_secrets_secrets_manager_arns                           = try(each.value.external_secrets_secrets_manager_arns, var.defaults.external_secrets_secrets_manager_arns, [])
  external_secrets_secrets_manager_create_permission              = try(each.value.external_secrets_secrets_manager_create_permission, var.defaults.external_secrets_secrets_manager_create_permission, false)
  external_secrets_ssm_parameter_arns                             = try(each.value.external_secrets_ssm_parameter_arns, var.defaults.external_secrets_ssm_parameter_arns, [])
  fsx_lustre_csi_service_role_arns                                = try(each.value.fsx_lustre_csi_service_role_arns, var.defaults.fsx_lustre_csi_service_role_arns, ["arn:aws:iam::*:role/aws-service-role/s3.data-source.lustre.fsx.amazonaws.com/*"])
  fsx_openzfs_csi_service_role_arns                               = try(each.value.fsx_openzfs_csi_service_role_arns, var.defaults.fsx_openzfs_csi_service_role_arns, ["arn:aws:iam::*:role/aws-service-role/fsx.amazonaws.com/*"])
  inline_policy_permissions                                       = try(each.value.inline_policy_permissions, var.defaults.inline_policy_permissions, null)
  load_balancer_controller_targetgroup_arns                       = try(each.value.load_balancer_controller_targetgroup_arns, var.defaults.load_balancer_controller_targetgroup_arns, [])
  max_session_duration                                            = try(each.value.max_session_duration, var.defaults.max_session_duration, null)
  mountpoint_s3_csi_bucket_arns                                   = try(each.value.mountpoint_s3_csi_bucket_arns, var.defaults.mountpoint_s3_csi_bucket_arns, [])
  mountpoint_s3_csi_kms_arns                                      = try(each.value.mountpoint_s3_csi_kms_arns, var.defaults.mountpoint_s3_csi_kms_arns, [])
  mountpoint_s3_csi_path_arns                                     = try(each.value.mountpoint_s3_csi_path_arns, var.defaults.mountpoint_s3_csi_path_arns, [])
  name                                                            = try(each.value.name, var.defaults.name, "")
  node_termination_handler_sqs_queue_arns                         = try(each.value.node_termination_handler_sqs_queue_arns, var.defaults.node_termination_handler_sqs_queue_arns, [])
  oidc_providers                                                  = try(each.value.oidc_providers, var.defaults.oidc_providers, {})
  override_inline_policy_documents                                = try(each.value.override_inline_policy_documents, var.defaults.override_inline_policy_documents, [])
  override_policy_documents                                       = try(each.value.override_policy_documents, var.defaults.override_policy_documents, [])
  path                                                            = try(each.value.path, var.defaults.path, "/")
  permissions                                                     = try(each.value.permissions, var.defaults.permissions, null)
  permissions_boundary                                            = try(each.value.permissions_boundary, var.defaults.permissions_boundary, null)
  policies                                                        = try(each.value.policies, var.defaults.policies, {})
  policy_description                                              = try(each.value.policy_description, var.defaults.policy_description, null)
  policy_name                                                     = try(each.value.policy_name, var.defaults.policy_name, null)
  policy_path                                                     = try(each.value.policy_path, var.defaults.policy_path, null)
  region                                                          = try(each.value.region, var.defaults.region, null)
  source_inline_policy_documents                                  = try(each.value.source_inline_policy_documents, var.defaults.source_inline_policy_documents, [])
  source_policy_documents                                         = try(each.value.source_policy_documents, var.defaults.source_policy_documents, [])
  tags                                                            = try(each.value.tags, var.defaults.tags, {})
  trust_condition_test                                            = try(each.value.trust_condition_test, var.defaults.trust_condition_test, "StringEquals")
  use_name_prefix                                                 = try(each.value.use_name_prefix, var.defaults.use_name_prefix, true)
  velero_s3_bucket_arns                                           = try(each.value.velero_s3_bucket_arns, var.defaults.velero_s3_bucket_arns, [])
  vpc_cni_enable_cloudwatch_logs                                  = try(each.value.vpc_cni_enable_cloudwatch_logs, var.defaults.vpc_cni_enable_cloudwatch_logs, false)
  vpc_cni_enable_ipv4                                             = try(each.value.vpc_cni_enable_ipv4, var.defaults.vpc_cni_enable_ipv4, false)
  vpc_cni_enable_ipv6                                             = try(each.value.vpc_cni_enable_ipv6, var.defaults.vpc_cni_enable_ipv6, false)
}
